package com.yunji.base.dao.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yunji.base.bo.ManagerSiteSelectBO;
import com.yunji.base.dao.IManagerSiteDao;
import com.yunji.base.domain.ManagerSiteDO;
import com.yunji.base.mapper.IManagerSiteMapper;
import com.yunji.common.base.BaseDaoImpl;
import com.yunji.common.utils.bean.BeanUtils;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author : peter-zhu
 * @date : 2024/12/11 16:37
 * @description : TODO
 **/
@Repository
public class ManagerSiteDaoImpl extends BaseDaoImpl<IManagerSiteMapper, ManagerSiteDO> implements IManagerSiteDao {
    @Override
    public ManagerSiteDO getByManagerId(Long managerId) {
        return lambdaQuery().eq(ManagerSiteDO::getManagerId, managerId).one();
    }

    @Override
    public boolean removeBatchBySiteIds(List<Long> siteIds) {
        return lambdaUpdate().in(ManagerSiteDO::getSiteId, siteIds).remove();
    }

    @Override
    public List<ManagerSiteDO> listBySiteIds(List<Long> siteIds) {
        return lambdaQuery().in(ManagerSiteDO::getSiteId, siteIds).list();
    }

    @Override
    public List<ManagerSiteDO> listByUserIds(List<Long> userIds) {
        return lambdaQuery().in(ManagerSiteDO::getManagerId, userIds).list();
    }

    @Override
    public ManagerSiteDO getBySiteId(Long siteId) {
        return lambdaQuery().eq(ManagerSiteDO::getSiteId, siteId).one();
    }

    @Override
    public ManagerSiteDO ManagerSiteSelectBO(ManagerSiteSelectBO bo) {
        return getOne(new LambdaQueryWrapper<ManagerSiteDO>()
                .eq(BeanUtils.isNotNull(bo.getId()), ManagerSiteDO::getId, bo.getId())
                .eq(BeanUtils.isNotNull(bo.getSiteId()), ManagerSiteDO::getSiteId, bo.getSiteId())
                .eq(BeanUtils.isNotNull(bo.getManagerId()), ManagerSiteDO::getManagerId, bo.getManagerId()));
    }
}
